<template>
  <div class="china_pages">
    <van-sticky>
      <van-nav-bar title="中国黄页" left-arrow @click-left="back" />
    </van-sticky>
    <div class="search">
      <label for=""> 企业名称</label>
      <input type="text" v-model="form.data.entName" placeholder="请输入关键字">
      <van-icon name="cross" @click="form.data.entName = ''" />
      <span @click="search">搜索</span>
		
    </div>
	<van-field
	  readonly
	  clickable
	  label="行业"
	  :value="value"
	  placeholder="选择行业"
	  @click="industryTag = true"
	/>
	<!-- <van-button round type="info" @click='industryFun'>行业筛选</van-button> -->

    <van-list v-model="loading" :finished="finished" finished-text="没有更多了" @load="getData">
      <div class="list">
        <div @click="rectTo(item)" class="company flex" v-for="(item,index) in dataList" :key="index">
          <div class="logo" :style="{backgroundImage:`url(${item.logoUrl})`}"></div>
          <div class="infor">
            <h4 class="name">{{item.entName}}</h4>
            <div class="tags flex">
              <span class="type1 row-between-center" v-if="item.levelName"><i class="icon"></i>{{item.levelName}}</span>
              <span class="type1 row-between-center" v-else><i class="icon"></i>未认证</span>
              <!-- <span class="type2"> {{item.}}</span> -->
              <span class="type2" v-if="item.industryTypeCN">{{item.industryTypeCN}}</span>
            </div>
            <div class="address flex">
              <i class="icon_address"></i>
              <span class="text">{{item.regionName}}</span>
            </div>
          </div>
          <div class="btn" v-if="item.levelName=='高级认证'">立即查看</div>
          <div class="btn" v-if="item.levelName!='高级认证'">意向咨询</div>
        </div>
      </div>
    </van-list>
		<van-popup v-model="industryTag" position="bottom">
				  <van-picker
				    show-toolbar
				    :columns="columns"
				    @cancel="showPicker = false"
				    @confirm="onConfirm"
					value-key="label"
				  />
				  </van-popup>

  </div>
</template>

<script>
import api from 'api/api'
import { Toast } from 'vant';
export default {
  data () {
    return {
      loading: false,
      finished: false,
      dataList: [],
	  industryTag:false,
	   columns: ['杭州', '宁波', '温州', '嘉兴', '湖州'],
	   value:'',
      form: {
        page: 0,
        data:{
          entName: '',
		  industryType:''
        }
       
      }
    }
  },
  created () {
    this.getData()
  },
  methods: {
		   onConfirm(value,index) {
			   console.log(value[0],index[0])
		        this.value = value[0];
		        this.industryTag = false;
				if(index[0]==0){
					this.form.data.industryType=''
				}
				else{
					this.form.data.industryType=index[0]-1
				}
				
				 this.form.page = 0
				this.dataList=[]
				this.getData()
		      },
		    sure(picker, value, index) {
		      Toast(`当前值：${value}, 当前索引：${index}`);
		    },
		    move() {
		      Toast('取消');
			  this.industryTag=false
		    },
	
		
    search () {
      this.form.page = 0
      this.dataList = []
      this.loading = false
      this.finished = false
      this.getData()
    },
    getData () {
      this.form.page++
      this.loading = true;
      api.yellowList(this.form).then(res => {
		  console.log(res.data)
        this.loading = false
        this.dataList = this.dataList.concat(res.data.records)
        if (this.form.page > res.data.pages - 1) {
          this.finished = true
        }
      })
	  api.dictIndustry().then(res=>{
		var str=[{'label':'全部','code':'','children':[]}]
		  this.columns=str.concat(res.data)
	
		  // console.log('wwww',res.data)
	  })
    },
    rectTo (item) {
		console.log(item)
			var level=localStorage.getItem('level')
		if(item.levelName=='高级认证'){
				this.$router.push('/company/' + item.id)
		}
		else if(item.levelName=='普通认证'){
					this.$router.push('/online/'+item.id)
		}
    },
    back () {
      window.history.go(-1)
    }
  }
}
</script>

<style lang="scss">
.china_pages {
  background-color: #f5f5f5;
  min-height: 100vh;
  .search {
    width: 6.9rem;
    margin: 0.2rem auto;
    background-color: #fff;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.32rem;
    padding: 0.1rem 0.2rem;
    border-radius: 0.5rem;
    label {
      display: flex;
      align-items: center;
      flex: none;
      i {
        transform: rotate(90deg);
      }
    }
    input {
      flex: auto;
      margin: 0 0 0 0.2rem;
      padding: 0.1rem 0.2rem;
      width: 3rem;
      background: none;
    }
    span {
      margin-left: 0.2rem;
       flex: none;
    }
  }
  .list {
    .company {
      padding: 0.27rem 0.27rem 0.41rem 0.27rem;
      background-color: #fff;
      margin-bottom: 0.17rem;
      position: relative;
      .logo {
        width: 1rem;
        height: 1rem;
        background-image: url("../../../assets/img/home/logo .png");
        background-size: cover;
      }
      .infor {
        text-align: left;
        margin-left: 0.2rem;
        .name {
          font-size: 0.3rem;
        }
        .tags {
          margin: 0.2rem 0;
          span {
            margin-right: 0.21rem;
            padding: 0.03rem 0.2rem;
          }
          .type1 {
            background: rgba(255, 241, 231, 1);
            border-radius: 0.07rem;
            color: #ff8a34;
            font-size: 0.22rem;
            .icon {
              width: 0.2rem;
              height: 0.23rem;
              background: url("../../../assets/img/home/renzheng .png");
              background-size: contain;
              background-repeat: no-repeat;
              background-position: center;
              margin-right: 0.05rem;
            }
          }
          .type2 {
            background: rgba(239, 246, 255, 1);
            border-radius: 7px;
            color: #348aff;
            font-size: 0.22rem;
            // padding: 0.1rem;
          }
        }
        .address {
          align-items: center;
          .icon_address {
            width: 0.27rem;
            height: 0.24rem;
            background: url("../../../assets/img/home/map.png");
            background-size: contain;
            background-repeat: no-repeat;
            background-position: center;
            margin-right: 0.1rem;
          }
          .text {
            font-size: 0.22rem;
          }
        }
      }
      .btn {
        position: absolute;
        right: 0.27rem;
        bottom: 0.27rem;
        width: 1.46rem;
        padding: 0.1rem 0.1rem;
        line-height: 1;
        text-align: center;
        font-size: 0.28rem;
        color: #fffefe;
        background: linear-gradient(
          96deg,
          rgba(72, 143, 240, 1),
          rgba(51, 130, 239, 1)
        );
        border-radius: 0.25rem;
      }
    }
  }
}
</style>